<%@page import="java.util.Date"%>
<%@page import="vo.ScheduleVO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="dto.ScheduleDTO"%>
<%@page import="java.util.Calendar"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:useBean id="vo" class="vo.ScheduleVO"/>
<jsp:setProperty property="*" name="vo"/>
<%
	ScheduleDTO dto = new ScheduleDTO();
	dto.setVo(vo);
	ArrayList<ScheduleVO> list = dto.getPrivateScheduleTodayContents((String)session.getAttribute("sessionMid"));

	if(session.getAttribute("sessionMid") != null){
		String m_id = (String)session.getAttribute("sessionMid");
	}else{
		%><script type="text/javascript">alert(m_id);</script> <%
		%><script type="text/javascript">alert("로그인 페이지로 이동 합니다.");</script> <%
		%><script type="text/javascript">location.href = "/group2/index/index.jsp";</script> <%
	}
%>
<title>calendar_today.jsp</title>
<link rel="stylesheet" href="${pageContext.request.contextPath }/css/calendar.css"/>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/calender.js"></script>
<script type="text/javascript">
	var PopLayer = {
		nowLayer : "",
		openLayer : "",
		Xpos : "",
		Ypos : "",
		Action : function(strAnchor, strLayer){
			this.nowLayer = strLayer;
			if(this.openLayer != ""){
				var objOpenLayer = document.getElementById(this.openLayer);
				objOpenLayer.style.display = "none";
				this.openLayer = "";
			}
			this.openLayer = strLayer;
			try{
				strAnchor.onmouseup = PopLayer.Open;
			} catch(e) {}
		},
		Open : function(e){
			if(document.all){
				this.Xpos = event.clientX-200;
				this.Ypos = event.clientY-200;
				alert("Xpos: "+Xpos);
				alert("Ypos: "+Ypos);
				if(this.Xpos < 1){
					this.Xpos = 20;
				}
				if(this.Ypos < 1){
					this.Ypos = 20;
				}
			} else {
				this.Xpos = e.clientX-200;
				this.Ypos = e.clientY-200;
				if(this.Xpos < 1){
					this.Xpos = 20;
				}
				if(this.Ypos < 1){
					this.Ypos = 20;
				}
			}
			var objNowLayer = document.getElementById(PopLayer.nowLayer);
			
			objNowLayer.style.left = document.body.scrollLeft + this.Xpos + "px";
			objNowLayer.style.top = document.body.scrollTop + this.Ypos + "px";
			objNowLayer.style.display = "block";
		},
		Close : function(){
			this.openLayer = "";
			var objNowLayer = document.getElementById(PopLayer.nowLayer);
			objNowLayer.style.display = "none";
		}
	}
</script>
<%
	int action = 0;
	int currYear = 0;
	int currMonth = 0;
	String boxSize = "70";
	
	Calendar c = Calendar.getInstance();
	Calendar cal = Calendar.getInstance();

	if (request.getParameter("action") == null){
		currMonth = c.get(c.MONTH);
		currYear = c.get(c.YEAR);
		cal.set(currYear, currMonth,1);
	}
	else{
		if(!(request.getParameter("action") == null)){
			currMonth = Integer.parseInt(request.getParameter("month"));
			currYear = Integer.parseInt(request.getParameter("year"));

			if(Integer.parseInt(request.getParameter("action")) == 1 ){
				cal.set(currYear, currMonth, 1);
				cal.add(cal.MONTH, 1);
				currMonth = cal.get(cal.MONTH);
				currYear = cal.get(cal.YEAR);
			}
			else{
				cal.set(currYear, currMonth , 1);
				cal.add(cal.MONTH, -1);
				currMonth = cal.get(cal.MONTH);
				currYear = cal.get(cal.YEAR);
			}
		}
	} 
%>
<%!public boolean isDate(int year, int month, int day){
		
		month -= 1;
        Calendar c = Calendar.getInstance();
        c.setLenient(false);

        try{
	        c.set(year, month, day);
	        Date dt = c.getTime();
        }catch (IllegalArgumentException e){
        	return false;
        }
       	return true;
    }%>
<%!public String getDateName (int monthNumber) {
		
		String strReturn = "";
		switch (monthNumber){ 
			case 0: strReturn = "1월"; break;
			case 1: strReturn = "2월"; break;
			case 2: strReturn = "3월"; break;
			case 3: strReturn = "4월"; break;
			case 4: strReturn = "5월"; break;
			case 5: strReturn = "6월"; break;
			case 6: strReturn = "7월"; break;
			case 7: strReturn = "8월"; break;
			case 8: strReturn = "9월"; break;
			case 9: strReturn = "10월"; break;
			case 10: strReturn = "11월"; break;
			case 11: strReturn = "12월"; break;
		}
		return strReturn;
    }%>
</head>
<body>
	<div id="contentGroup">
		<h3 style="font-size: 30px; font-family: 돋움;">오늘 일정</h3>
		<table border="0" width="900" height="20" style="margin-bottom: 10px; table-layout: fixed;">
			<tr>
				<td width="150" align="center" valign="middle"><a href="${pageContext.request.contextPath }/index/main.jsp?inc=../schedule/schedule_private.jsp?date=<%= %>month=<%=currMonth%>&year=<%=currYear%>&action=0&left_menu=../schedule/schedule_menu.jsp" style="text-decoration: none;"><font class="arrow" size="4" face="돋움" color="black">◀</font></a></td>		
				<td width="260" align="center" valign="middle"><div style="font-family: 돋움; font-size: 30px; font-weight: bold;0"><%=cal.get(cal.YEAR)+"년&nbsp&nbsp"+getDateName(cal.get(cal.MONTH))%></div></td>
	 			<td width="150" align="center" valign="middle"><a href="${pageContext.request.contextPath }/index/main.jsp?inc=../schedule/schedule_private.jsp?month=<%=currMonth%>&year=<%=currYear%>&action=1&left_menu=../schedule/schedule_menu.jsp" style="text-decoration: none;"><font class="arrow" size="4" face="돋움" color="black">▶</font></a></td>
			</tr>
		</table>
	</div>
	<div id="content">
		<div id="calenderTab">
			<table  border="1" width="1000" bgcolor="#DFDCD8" style="border-collapse: collapse;">
				<tr>
					<td width="50" colspan="2" height="15px" align="center" bgcolor="#666666">
						<font color="#FFFFFF" face="돋움" size="2"><b>오늘 일정</b></font>
					</td>
				</tr>
				<%for(int i=7; i<=24; i++){ %>
					<%String time = String.valueOf(i); %>
					<tr height="27">
						<td width="35" align="right" style="padding-right: 5px; font-family: 돋움; font-size: 14px" onmousedown="PopLayer.Action(this, 'layer<%=i %>')"><%=i %>시</td>
						<td onmousedown="PopLayer.Action(this,'layer<%=i %>')">
							
						</td>
					</tr>
				<%} %>		
			</table>
		</div>
	</div>
	<%for(int i=7; i<=24; i++){ %>
		<div id="layer<%=i %>" style="border: solid 1px #8C8C8C; width: 400px; height: 75px; display:none; position:absolute; left:0; top:0; padding: 10px; background-color: #F6F6F6; font-size:12px; font-family: 돋움; color: black;">
			<%if(i<10){ %>
				<font size="4" style="text-align: left;"> 0<%=i %>시 일정</font>
			<%}else{ %>
				<font size="4" style="text-align: left;"> <%=i %>시 일정</font>
			<%} %>
			<form name="frm_today" method="post">
				<br/><font size="2" style="text-align: left;"> 오늘의 일정을 입력하세요.</font>
				<input id="m_id" name="m_id" type="hidden" value="<%=session.getAttribute("sessionMid") %>"/>
				<input id="schedule_date" name="schedule_date" type="hidden" value=""/>
				<input id="schedule_time" name="schedule_time" type="hidden" value="<%=i %>"/>
				<input id="schedule_division" name="schedule_division" type="hidden" value="private"/>
				<input id="schedule_today_contents" name="schedule_today_contents" type="text" size="25"/>
				<input id="schedule_today_insert" name="schedule_today_insert" type="submit" value="입력" formaction="/group2/schedule_today_insert.do"/>
				<input id="schedule_today_delete" name="schedule_today_update" type="submit" value="수정" formaction="/group2/schedule_today_update.do"/>
				<input id="schedule_today_delete" name="schedule_today_delete" type="submit" value="삭제" formaction="/group2/schedule_today_delete.do"/>
				<input type="button" value="닫기" onclick="PopLayer.Close()"/>
			</form>
		</div>
	<%} %>
</body>
</html>